package com.zirenx.utils;

import com.zirenx.sys.model.SysUser;

import javax.servlet.http.HttpServletRequest;

public class SysUserUtils {

    private static final String USER_KEY = "session_user";

    public static void setUser(SysUser sysUser, HttpServletRequest request){
        request.getSession().setAttribute(USER_KEY,sysUser);
    }

    public static SysUser getUser(HttpServletRequest request){
        return (SysUser)request.getSession().getAttribute(USER_KEY);
    }

    public static String getUsername(HttpServletRequest request){
        SysUser user = getUser(request);
        if (user!=null){
            return user.getUsername();
        }
        return null;
    }

    public static Long getUserId(HttpServletRequest request){
        SysUser user = (SysUser)request.getSession().getAttribute(USER_KEY);
        if(user!=null) {
        	return user.getId();
        }
		return null;
    }
}
